package com.epam.DAO.JPA;

import javax.persistence.EntityManager;
import javax.persistence.TypedQuery;

import com.epam.DAO.UserDAO;
import com.epam.entity.User;

public class UserDAOJPA extends GenericDAOJPA<User> implements UserDAO {

	public UserDAOJPA() {
		super(User.class);
	}

	@Override
	public User read(String login, String pass) {
		EntityManager em = getEntityManager();
		TypedQuery<User> query = em
				.createQuery(
						"SELECT u FROM User u WHERE u.login = :login AND u.pass =: pass",
						User.class);
		query.setParameter("login", login);
		query.setParameter("pass", pass);
		User user = query.getSingleResult(); 
		em.close();
		return user;
	}

}
